<?php if (IS_USER_LOGGED_IN) { ?>
    <div><a href="<?= $this->L('user', 'logout'); ?>" style="color:red; cursor:pointer;">登出</a></div><br />
<?php } ?>
<script type="text/javascript" charset="utf-8" src="<?= WEB_URL ?>/js/kindeditor/kindeditor-min.js"></script>
    	<div class="fl">
			<div class="letterArea">
				<div class="letterList">
					<ul>
						<?php
						if ($this->paginator) {
							$blogs = $this->paginator->getItemsByPage(0);
							foreach ($blogs as $b) {
						?>
							<li class="letterItem">
								<span style="font-size:16px; margin:16px 0 13px; display:inline-block;"><?= !empty($b['praised_name']) ? ('致“' . $b['praised_name'] . '”') : '感谢'; ?>：</span>
								<div style=" line-height:21px; height:230px; overflow:auto;text-indent:2em;"><?= $b['text']; ?></div>
								<div style=" position:absolute; height:25px; overflow:hidden;bottom:8px; left:25px;"><a href="#" class="ding">123</a></div>
								<?php if (IS_USER_LOGGED_IN) { ?>
									<div>
										<a style="color:red; cursor:pointer;" onclick="deleteBlog('<?= $b['id'] ?>')">删除它？</a>
									</div>
								<?php } ?>
							</li>
						<?php
							}
						}
						?>
					</ul>
				</div>
				<!--<div style="display: none;" class="letterShow_controls">
					<a id="ss_button_prev" href="javascript:void(0);" class="ss_button_icon"></a>
					<a id="ss_button_pause_play" href="javascript:void(0);" class="ss_button_icon ss_button_pause"></a>
					<a id="ss_button_next" href="javascript:void(0);" class="ss_button_icon"></a>
				</div>-->
			</div>
			<div><?php echo $this->paginator; ?></div>
		</div>
		<div class="formArea">
        	<form id="form_add_question" enctype="application/x-www-form-urlencoded" method="post" action="">
            	<table width="100%"  cellspacing="0">
                  <tr>
                    <td height="35" valign="top" width="100%">我的 Email :</td>
                    <td valign="top"><?= $this->formAddQuestion->sender_email->renderViewHelper(); ?></td>
                  </tr>
                  <tr>
                    <td height="35" valign="top">被表扬人昵称 :</td>
                    <td valign="top"><?= $this->formAddQuestion->praised_name->renderViewHelper(); ?></td>
                  </tr>
                  <tr>
                    <td height="35" valign="top">被表扬人Email:</td>
                    <td valign="top"><?= $this->formAddQuestion->praised_email->renderViewHelper(); ?></td>
                  </tr>
                  <tr>
                    <td height="35" valign="top">表扬信内容 :</td>
                    <td valign="top"></td>
                  </tr>
                     <tr >
                    <td height="35" colspan="2" style="padding-bottom:15px;">
						<?= $this->formAddQuestion->text->renderViewHelper(); ?>
					</td>
                   </tr>
                  <tr>
                    <td height="35" valign="top"><a href="javascript:void(0)" class="addOthersEmail" onclick="javascript:addReceiverEmailAdv();">+</a>群发 Email：</td>
                    <td valign="top" class="othersEmailArea">
                        <?= $this->formAddQuestion->receiver_email->renderViewHelper(); ?>
                    </td>
                  </tr>

                  <tr>
                    <td height="35" valign="top"><input  id="submit" type="submit" class="button mt5" value="提交" /></td>
                    <td valign="top">&nbsp;</td>
                  </tr>
                </table>
            </form>
        </div>
		<div class="othersEmailTpl" style=" display:none;">
                <div style="margin-top:5px">
                    <input type="text" name="receiver_email_adv[]" title="收信者邮箱" />
					<!--<?= $this->formAddQuestion->receiver_email->renderViewHelper(); ?>-->
				</div>
        </div>


<script type="text/javascript">
function addReceiverEmailAdv()
{
    if ($('#form_add_question .othersEmailArea div').length < 10) {
        $('#form_add_question .othersEmailArea').append($('.othersEmailTpl').html());
    } else {
        return false;
    }
};

function deleteBlog(id)
{
    if (confirm('你真的确定要删除这篇文章吗？')) {
        location.href = "<?= $this->L('index', 'delete-post'); ?>/id/" + id;
    } else {
        return false;
    }
};

KE.show({
    id : 'text',
    resizeMode : 1,
    syncType : 'auto',
    //imageUploadJson : '<?= $this->L('blog', 'editor-upload') ?>',
    items : ['bold', 'italic', 'underline', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link']
});
</script>
<script type="text/javascript">
$().ready(function() {
    $('#sender_email').poshytip({
        className: 'tip-twitter',
        showOn: 'focus',
        alignTo: 'target',
        alignX: 'right',
        alignY: 'center',
        offsetX: 5
    });
    $('#receiver_email').poshytip({
        className: 'tip-twitter',
        showOn: 'focus',
        alignTo: 'target',
        alignX: 'right',
        alignY: 'center',
        offsetX: 5
    });
    $('#praised_email').poshytip({
        className: 'tip-twitter',
        showOn: 'focus',
        alignTo: 'target',
        alignX: 'right',
        alignY: 'center',
        offsetX: 5
    });
	$('#praised_name').poshytip({
        className: 'tip-twitter',
        showOn: 'focus',
        alignTo: 'target',
        alignX: 'right',
        alignY: 'center',
        offsetX: 5
    });

    $('#text').poshytip({
        className: 'tip-twitter',
        showOn: 'focus',
        alignTo: 'target',
        alignX: 'right',
        alignY: 'center',
        offsetX: 5
    });
});
</script>
<script type="text/javascript">
$().ready(function() {
	//letter Show controls
		$('.letterList').hover(function(){ $('.letterArea .letterShow_controls').show();},
		function(){ $('.letterArea .letterShow_controls').hide();}
	);
	$('.letterArea .letterShow_controls').hover(function(){ $(this).show();},
		function(){ $(this).show();}
	);
    //random the letter style
	$('.letterList .letterItem').each(function(){
	  		$(this).addClass('style' +Math.round(Math.random()*(2) + 1));
	});
	$('.letterList .letterItem').eq(0).addClass('current');
	// regex method for validator
    $.validator.addMethod(
        "regex",
        function(value, element, regexp) {
            var check = false;
            var re = new RegExp(regexp);
            return this.optional(element) || re.test(value);
        },
        "Please check your input"
    );
	 $.validator.addMethod(
        "RegisterRequired",
        function(value, element, regexp) {
            if ($(element).parent().parent().prev().find('label.error').length!=0 ||
                $(element).parent().parent().prev().find('input').val()==''||
                $(element).parent().parent().prev().find('select').val()=='') {
                return true;
            } else {
                if ($(element).val() == '') {
                    return false;
                } else {
                    return true;
                }
            }
        },
        ""
    );
    // register form validate
    $("#form_add_question").validate({
        rules: {
            sender_email: {
                required: true,
                email: true
            },
			praised_name: {
                required: true
            },
            praised_email: {
                email: true
            },
            text: {
                required: true,
                minlength: 10
            },
            receiver_email: {
                required: true,
                email: true
            }
        },
		messages: {
            sender_email: {
                required: "请正确地填写发信人的邮箱地址",
                email: "请正确地填写发信人的邮箱地址"
            },
			praised_name: {
                required: "请正确地填写被表扬人的昵称"
            },
            praised_email: {
                required: "请正确地填写被表扬人的邮箱地址",
                email: "请正确地填写被表扬人的邮箱地址"
            },
            text: {
                required: "请填写表扬信的内容",
                minlength: "表扬信的内容应多于10个字"
            },
            receiver_email: {
                required: "请正确地填写收信人的邮箱地址",
                email: "请正确地填写收信人的邮箱地址"

            }
        },
        onkeyup: false,
        onblur: true

    });
/*
	$(".letterList").jCarouselLite({
        speed: 1000,
        auto:3000,
		mouseWheel:true,
		vertical:true,
		circular:true,
		visible:1
    }); */
});
//letter show
		function slideSwitch() {			
			var $current = $(".letterArea .current");
			if ( $current.length == 0 ) $current = $(".letterArea .letterItem:last");
			var $next = $current.next().length ? $current.next() : $(".letterArea .letterItem").eq(0);
			 $current.addClass('prev');
			$next.css({opacity:0}).addClass("current").animate({opacity:1},500,function(){$current.removeClass("current prev");});
			}
		 setInterval( "slideSwitch()", 5000 );
</script>